"""
Run this file to run the game.
"""

####IMPORTS####
import pygame, os
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((0,0), FULLSCREEN)
pygame.mouse.set_visible(False)
from qnd import *
from kiwi import Kiwi
from box import Box

####CONSTANTS####
FRAMERATE = 60

####FUNCTIONS####
def play_level(level,screen):
	"""Loads the level file with the name level and plays it."""
	
	####Initiate Some Stuff
	tilemap = load_tilemap(level)
	tileset = load_tileset('tileset_1.png','images')
	camera = Camera(screen,maxx=tileset[0].get_width()*len(tilemap), maxy=tileset[0].get_height()*len(tilemap[0]))
	clock = pygame.time.Clock()
	kiwi = Kiwi((100,500))
	
	####The main loop
	while True:
		
		####Update Objects
		input.update()
		
		if K_F1 in input.keyspressed:
			play_level(level,screen)
		
		kiwi.update(input, tilemap, tileset[0].get_size())
		
		#make camera follow kiwi.
		kiwiOffset = kiwi.x-(camera.x+screen.get_width()/2)
		camera.move((kiwiOffset/100,0),relative=True)
		
		####Drawing Stuff
		draw_tiles(screen, tilemap, tileset, camera)
		kiwi.draw(screen,camera)
		pygame.display.flip()
		
		####Wait till next frame
		clock.tick(FRAMERATE)

	
####INITIALIZE####
input = InputHandler()
screen.fill((40,160,200))
draw_text(screen, "Kiwi  Warrior", ('c','c'),pygame.font.Font(None,200))
pygame.display.flip()
pygame.time.wait(1000)
play_level("level_1",screen)
